#include "ZBox.h"

namespace Zdib
{

	CBox::CBox(CContainer *root,CContainer *parent, int w, int h, TColor color, BYTE alpha):CContainer(parent)
	{
		W=w;
		H=h;
		m_Color=color;
		m_Alpha=alpha;
		m_Img=new CImgFile();
		m_Img->SetSize(w,h);
		m_Img->FillColor(color);
		m_Img->SetAlpha(alpha);
		SetRoot(root);
	}

	CBox::~CBox()
	{
		delete m_Img;
	}

	void CBox::SetSize(int w,int h)
	{
		m_Img->SetSize(w,h);
		W=w;
		H=h;
	}

	void CBox::Draw()
	{	
		CImgFile *desimg;
		if(!m_Show)
			return;
		desimg=m_Parent->GetCurImg();
		if(desimg)
		{
			if(m_RefrashDrawPos)
			{
				m_DPosValue=CalDrawPosValue(m_Img->GetWidth(),m_Img->GetHeight(),ScreenX,ScreenY);
			}
			if(m_Alpha==0)
				desimg->Draw(m_Img,ScreenX,ScreenY,false,&m_DPosValue);
			else
				desimg->Draw(m_Img,ScreenX,ScreenY,true,&m_DPosValue);
		}
		CContainer::Draw();
	}

	bool CBox::OnEvent(const TEvent& ev)
	{
		if(ev.event_type==ET_MouseEvent)
		{
			if(myEventReceiver!=NULL)
			{
				Zdib::TEvent newev;
				newev=ev;
				newev.Mouse.Call=this;
				newev.Mouse.CallBack=NULL;
				return myEventReceiver->OnEvent(newev);
			}
			else
			{
				return m_Parent->OnEvent(ev);
			}
		}
		return false;
	}
}